import { Component, OnInit, OnDestroy } from '@angular/core';
import { ReportUrls } from 'app/ptpmc/comm/report.urls.conf';
import { LocalStorage } from 'app/ptpmc/localstorage/local.storage';
import { CommService } from 'app/ptpmc/comm/comm.service';
import { WebSocketService } from 'app/ptpmc/comm/websocket-service';
import { GlobalDataManager } from 'app/ptpmc/comm/global-data-manager';
import { Project } from 'app/ptpmc/model/comm/config-data';
//import Enumerable = require('linq');
declare var h5_android;

@Component({
  selector: 'app-plane',
  templateUrl: './plane.component.html',
  styleUrls: ['./plane.component.scss']
})
export class PlaneComponent implements OnInit, OnDestroy {

  height;
  timeNow;
  production = [];
  production2 = [];
  production3 = [];
  listNow = [];
  listNow2 = [];
  listNow3 = [];
  listHistory = [];
  listHistory2 = [];
  listHistory3 = [];
  audioList = [];
  alarmMessage = [];
  isCSS1 = false;
  isGF9 = false;
  isBEV = false;
  isK226 = false;
  isBEV3 = false;
  isCSS5 = false;
  isGFE2 = false;
  isHEV2 = false;
  isUBEV = false;
  isPHEV = false;
  timeInterval;
  projectSelected = null;
  projectSelectedDesc = '';
  connStatus = false;
  public projectItems: Project[] = [];
  constructor(private wsService: WebSocketService, private ls: LocalStorage, private commServices: CommService) { }

  ngOnInit() {
    //this.commServices.getCurrentProject();
    this.projectSelected = GlobalDataManager.getProjectSelected().projectName;
    this.projectSelectedDesc = GlobalDataManager.getProjectSelected().projectDesc;
    if (this.projectSelected === 'CSS1') {
      this.isCSS1 = true;
      this.isGF9 = false;
      this.isBEV = false;
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = false;
    } else if (this.projectSelected === 'GF9') {
      this.isGF9 = true;
      this.isCSS1 = false;
      this.isBEV = false;
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = false;
    } else if (this.projectSelected === 'B121') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = true;
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = false;
    } else if (this.projectSelected === 'K226') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = false;
      this.isK226 = true;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = false;
    }else if (this.projectSelected === 'CSS5') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = false;
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = true;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = false;
    }else if (this.projectSelected === 'BEV3') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = false;
      this.isK226 = false;
      this.isBEV3 = true;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = false;
    }else if (this.projectSelected === 'GFE2') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = false;
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = true;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = false;
    }else if (this.projectSelected === 'NCXB') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = false;
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = true;
      this.isUBEV = false;
      this.isPHEV = false;
    }else if (this.projectSelected === 'UBEV') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = false; 
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = true;
      this.isPHEV = false;
    }else if (this.projectSelected === 'PHEV') {
      this.isGF9 = false;
      this.isCSS1 = false;
      this.isBEV = false; 
      this.isK226 = false;
      this.isBEV3 = false;
      this.isCSS5 = false;
      this.isGFE2 = false;
      this.isHEV2 = false;
      this.isUBEV = false;
      this.isPHEV = true;
    }

    this.refreshHistory();

    // this.timeInterval = setInterval(() => {
    //   this.timeNow = this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
    // }, 1000);

    const timeAudioInterval = setInterval(() => {
      if (this.audioList && this.audioList.length > 0) {
        const brower = navigator.userAgent;
        const currentAudio = this.audioList.shift();
        if (brower.indexOf('Android') !== -1) {
          h5_android.playMp3(currentAudio.value);
        } else {
          const a = document.createElement('audio');
          a.src = currentAudio.value;
          // console.log(currentAudio.value)
          a.play();
        }
      }
    }, 3000);

    setInterval(() => {
      this.refreshHistory();
    }, 2000 * 60)


    this.connWs();

  }


  connWs() {
    try {
      if (this.wsService && this.wsService.ws) { this.wsService.ws.close(); }
    } catch (e) {

    }
    const url = ReportUrls.BaseUrl.replace('http://', '');
    this.wsService.createObservableSocket(`ws://${url}/ws?uid=${this.ls.get('ptpmc_userId')}`)
      .subscribe(
        data => {
          this.connStatus = true;
          // console.log(data);
          try {
            const res = JSON.parse(data);
            if (res.key === 'exit') {
              // alert('当前账户在其它电脑登录！');
            } else if (res.key === 'play_wav_plane') {
              const wavUrl = ReportUrls.BaseUrl + res.value;
              res.value = wavUrl;
              this.audioList.push(res);
            } else if (res.key === 'prodState') {
              const value = JSON.parse(res.value);
              this.production = [];
              this.production2 = [];
              this.production3 = [];
              if (this.projectSelected === 'CSS1') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  if (subArea == 'BL' || subArea == 'HL') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else if (subArea == 'KL') {
                    this.production2.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production3.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'GF9') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  if (subArea == 'AL1' || subArea == 'BA1' || subArea == 'CA1' || subArea == 'HA1' || subArea == 'SA1' || subArea == 'VA1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production3.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'B121') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  
                  if (subArea == 'ST1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else if (subArea == 'PK1') {
                    this.production2.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production3.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'K226') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  debugger
                  if (subArea == 'LC3') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production3.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'CSS5') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  if (subArea == 'BL1' || subArea == 'HL1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else if (subArea == 'KL1') {
                    this.production2.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production3.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'BEV3') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  if (subArea == 'PK1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'GFE2') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  if (subArea == 'AL1' || subArea == 'BU1' || subArea == 'TC1' || subArea == 'CS1' || subArea == 'CR1' || subArea == 'DH1' || subArea == 'TD1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production3.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'NCXB') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;
                  if (subArea == 'ST1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else if(subArea == 'CM1') {
                    this.production2.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }else {
                    this.production3.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                });
              } else if (this.projectSelected === 'UBEV') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph; 
                  if (subArea == 'ST1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production2.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                }); 
              } else if (this.projectSelected === 'PHEV') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const equipment = item.equipment;
                  const hours = item.hours;
                  const unhours = item.unhours;
                  const jph = item.jph;   
                  if (subArea == 'CB1') {
                    this.production.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  } else {
                    this.production2.push({ subArea: subArea, equipment: equipment, hours: hours, unhours: unhours, jph: jph });
                  }
                }); 
              }

            } else if (res.key === 'fault') {
              const value = JSON.parse(res.value);
              this.listNow = [];
              this.listNow2 = [];
              this.listNow3 = [];
              if (this.projectSelected === 'CSS1') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'CSBL1' || subArea == 'CSHL1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else if (subArea == 'CSKL1') {
                    this.listNow2.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow3.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'GF9') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'G9AL1' || subArea == 'G9BA1' || subArea == 'G9CA1' || subArea == 'G9HA1' || subArea == 'G9SA1' || subArea == 'G9VA1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow3.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'B121') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'BEST1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else if (subArea == 'BEPK1') {
                    this.listNow2.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow3.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'K226') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'BPLC3') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow3.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'CSS5') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'C5BL1' || subArea == 'C5HL1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else if (subArea == 'C5KL1') {
                    this.listNow2.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow3.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'BEV3') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'BEPK1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'GFE2') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'GFAL1' || subArea == 'GFBU1' || subArea == 'GFTC1' || subArea == 'GFCS1' || subArea == 'GFCR1' || subArea == 'GFDH1' || subArea == 'GFTD1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow3.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'HEV2') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'HEST1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else if(subArea == 'HECM1') {
                    this.listNow2.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow3.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'UBEV') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'STUBST1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow2.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              } else if (this.projectSelected === 'PHEV') {
                value.forEach(item => {
                  const subArea = item.subArea;
                  const station = item.station;
                  const duration = item.duration;
                  const code = item.code;
                  const faultWordDescription = item.faultWordDescription;

                  if (subArea == 'CBPHCB1') {
                    this.listNow.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  } else {
                    this.listNow2.push(
                      { subArea: subArea, station: station, duration: duration, code: code, faultWordDescription: faultWordDescription }
                    );
                  }
                });
              }
            }
          } catch (e) {

          }
        },
        err => { console.log(err); },
        () => {
          console.log('连接断开');
          this.connStatus = false;
        }
      );
  }



  ngOnDestroy(): void {
    if (this.timeInterval) {
      clearInterval(this.timeInterval);
    }
  }
  formatDate(date: Date, fmt) {
    const o = {
      'M+': date.getMonth() + 1, // 月份
      'd+': date.getDate(), // 日
      'h+': date.getHours(), // 小时
      'm+': date.getMinutes(), // 分
      's+': date.getSeconds(), // 秒
      'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
      'S': date.getMilliseconds() // 毫秒
    };
    if (/(y+)/.test(fmt)) {
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
    };
    for (const k in o) {
      if (new RegExp('(' + k + ')').test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
      }
    }
    return fmt;
  }

  refreshHistory() {
    this.commServices
      .doGet('/tip/filter/list/current')
      .subscribe(model => {
        if (model.resultCode === 200) {
          this.listHistory = [];
          this.listHistory2 = [];
          this.listHistory3 = [];
          if (this.projectSelected === 'CSS1') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'CSBL1' || subArea == 'CSHL1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else if (subArea == 'CSKL1') {
                this.listHistory2.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else {
                this.listHistory3.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          } else if (this.projectSelected === 'GF9') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'G9AL1' || subArea == 'G9BA1' || subArea == 'G9CA1' || subArea == 'G9HA1' || subArea == 'G9SA1' || subArea == 'G9VA1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else {
                this.listHistory3.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          } else if (this.projectSelected === 'B121') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'BEST1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else if (subArea == 'BEPK1') {
                this.listHistory2.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else {
                this.listHistory3.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          } else if (this.projectSelected === 'CSS5') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'C5BL1' || subArea == 'C5HL1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else if (subArea == 'C5KL1') {
                this.listHistory2.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else {
                this.listHistory3.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          } else if (this.projectSelected === 'BEV3') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'BEPK1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          } else if (this.projectSelected === 'GFE2') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'GFAL1' || subArea == 'GFBU1' || subArea == 'GFTC1' || subArea == 'GFCS1' || subArea == 'GFCR1' || subArea == 'GFDH1' || subArea == 'GFTD1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else {
                this.listHistory3.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          } else if (this.projectSelected === 'HEV2') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'HEST1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else if (subArea == 'HECM1') {
                this.listHistory2.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else {
                this.listHistory3.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          } else if (this.projectSelected === 'UBEV') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'STUBST1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription }); 
                } else {
                  this.listHistory2.push(
                    { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
                }
              });
          } else if (this.projectSelected === 'PHEV') {
            model.data.forEach(e => {
              const subArea = e.subArea;
              const duration = (Number.parseInt(e.duration) / 60).toFixed(0);
              if (subArea == 'CBPHCB1') {
                this.listHistory.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              } else {
                this.listHistory2.push(
                  { subArea: subArea, station: e.station, duration: duration, shfitDay: e.startTime.split(" ")[1], deviceAlarmNo: e.deviceAlarmNo, faultWordDescription: e.faultWordDescription });
              }
            });
          }
        }
      });
  }

  refreshAlarmMessage() {
      this.commServices
      .doGet('/tip/filter/list/msg')
      .subscribe(model => {
        if (model.resultCode === 200) {
          this.alarmMessage = model.data.map(e => e.faultWordDescription);
        }
      });
  }

}
